#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int a[N];
int f[N];
int n;
int len;
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++)
    {
        if (len == 0 || a[i] > f[len])
        {
            f[++len] = a[i];
        }
        else
        {
            int l = 1;
            int r = len;
            while (l < r)
            {
                int mid = (r + l) / 2;
                if (f[mid] >= a[i])
                {
                    r = mid;
                }
                else
                {
                    l = mid + 1;
                }
            }
            f[l] = a[i];
        }
    }
    cout << len;
    return 0;
}